package com.ruoyi.web.controller.formwork;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.formwork.domain.OperationFormWork;
import com.ruoyi.formwork.domain.WarnFormWork;
import com.ruoyi.formwork.service.WarnFormWorkService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.success;


@RestController
@RequestMapping("/WarnFormWorkController")
public class WarnFormWorkController {

    @Resource
    private WarnFormWorkService WarnFormWorkService;

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.setDisallowedFields(new String[]{"admin"});
    }
    @Log(title = "基线告警查询", businessType = BusinessType.QUERY)
    @PostMapping("/queryWarnFormWork")

    public AjaxResult queryWarnFormWork(@RequestBody WarnFormWork WarnFormWork)
    {

        List<WarnFormWork> WarnFormWorks = WarnFormWorkService.queryWarnFormWork(WarnFormWork);
        return success(WarnFormWorks);
    }

    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarnFormWork WarnFormWork)
    {
        List<WarnFormWork> WarnFormWorks = WarnFormWorkService.queryWarnFormWork(WarnFormWork);

        ExcelUtil<WarnFormWork> util = new ExcelUtil<WarnFormWork>(WarnFormWork.class);

        util.exportExcel(response, WarnFormWorks, "告警模板");
    }
    @Log(title = "基线告警删除", businessType = BusinessType.DELETE)
    @PostMapping("/deleteWarnFormWork")
    public AjaxResult deleteWarnFormWork(@RequestBody WarnFormWork WarnFormWork)
    {
        boolean b = WarnFormWorkService.deleteWarnFormWork(WarnFormWork);
        if(b){
            return success("删除成功！");
        }else{
            return success("删除失败！");
        }

    }
    @Log(title = "基线告警新增", businessType = BusinessType.INSERT)
    @PostMapping("/addWarnFormWork")
    public AjaxResult addWarnFormWork(@RequestBody WarnFormWork WarnFormWork)
    {
        boolean b = WarnFormWorkService.save(WarnFormWork);
        if(b){
            return success("新增成功！");
        }else{
            return success("新增失败！");
        }

    }
    @Log(title = "基线告警修改", businessType = BusinessType.UPDATE)
    @PostMapping("/updateWarnFormWork")
    public AjaxResult updateWarnFormWork(@RequestBody WarnFormWork WarnFormWork)
    {
        boolean b = WarnFormWorkService.updateById(WarnFormWork);
        if(b){
            return success("修改成功！");
        }else{
            return success("修改失败！");
        }

    }

    @PostMapping("/queryWarnFormWorkById")
    public AjaxResult queryWarnFormWorkById(@RequestBody WarnFormWork WarnFormWork)
    {
        WarnFormWork model = WarnFormWorkService.getById(WarnFormWork.getId());
        return success(model);

    }
}
